% /*******************************************************************************
%  * Simulate Truncated Multiplication
%  * *****************************************************************************
%  * It is assumed that a and b are unsigned fractions with a,b in [0,1). 
%  * The algorithm is simple: truncate Partial Products (keep only r+k leftmost 
%  * bits), add the correction constant and finally round the result to r bit.
%  *               
%  * @param a     Multiplicand
%  * @param b     Multiplier
%  * @param corr_const    Correction Constant(CC)
%  * @param m     Multiplicand Width
%  * @param n     Multiplier Width
%  * @param r     Result Width  
%  * @param k     Extra bit to keep
%  * @return      Rounded product
%  */
function [p,s] = trunc_mult(a, b, corr_const, m, n, r, k)
p = 0;
for i = 0 : n-1
    b = 2 * b;
    a = 0.5 * a;
    if (b >= double(1))
        p = rnd_down(p + a, r + k);
        b = double(b - 1.0);
    end
end
s = p + corr_const;
p = rnd_down(p + corr_const, r);
end